package com.example.liuxing.android.activity.utils;

import android.content.Context;
import android.content.SharedPreferences;

import com.example.liuxing.android.activity.config.Constant;

/**
 * Created by liuxing on 2017/6/28.
 */

public class SPUtils {

    public static SharedPreferences getSp(Context context) {
        SharedPreferences sp = context.getSharedPreferences(Constant.SPNAME, Context.MODE_PRIVATE);
        return sp;
    }

    //得到sp里面保存的boolean
    public  static boolean getBoolean(Context context,String key) {
        SharedPreferences sp = getSp(context);
        return sp.getBoolean(key,false);
    }

    //往sp保存一个Boolean
    public  static void  putBoolean(Context context,String key ,boolean  state) {
        SharedPreferences sp = getSp(context);
        sp.edit().putBoolean(key,state).commit();
    }

    //得到sp里面保存的boolean
    public  static String getString(Context context, String key) {
        SharedPreferences sp = getSp(context);
        return sp.getString(key, null);
    }

    //往sp保存一个Boolean
    public static void putString(Context context, String key, String text) {
        SharedPreferences sp = getSp(context);
        sp.edit().putString(key, text).commit();
    }
}
